Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(events): Update and Add Cognito User Pool Events #4423

Merged
merged 6 commits into from
Jun 12, 2024

Conversation

knightmre
Copy link

@knightmre knightmre commented May 29, 2024

Issue number: #3987

Summary

Changes

Please provide a summary of what's being changed

This change updates the UserMigrationTriggerEvent data class, adds the V2 of Pre Token Generation Lambda Triggers and adds two new data classes for Custom Sender Lambda triggers

User experience

Please share what the user experience looks like before and after this change

Events did not exist before. A workaround was to self-implement the data classes by inheriting base classes like so:

Before

from typing import Optional

from aws_lambda_powertools.utilities.data_classes import cognito_user_pool_event
from aws_lambda_powertools.utilities.data_classes import common


class CustomSMSSenderTriggerEventRequest(common.DictWrapper):
    @property
    def code(self) -> str:
        """A string for you to use as the placeholder for the verification code in the custom message."""
        return self["request"]["code"]

    @property
    def user_attributes(self) -> dict[str, str]:
        """One or more name-value pairs representing user attributes. The attribute names are the keys."""
        return self["request"]["userAttributes"]

    @property
    def client_metadata(self) -> Optional[dict[str, str]]:
        """One or more key-value pairs that you can provide as custom input to the Lambda function
        that you specify for the pre sign-up trigger."""
        return self["request"].get("clientMetadata")


class CustomSMSSenderEvent(cognito_user_pool_event.BaseTriggerEvent):

    @property
    def request(self) -> CustomSMSSenderTriggerEventRequest:
        return CustomSMSSenderTriggerEventRequest(self._data)
from . import CustomSMSSenderEvent

@data_classes.event_source(data_class=CustomSMSSenderEvent)
def handler(event: CustomSMSSenderEvent, context):
    return handle_event(event=event)

After

from aws_lambda_powertools.utilities.data_classes.cognito_user_pool_event import CustomSMSSenderTriggerEvent

@data_classes.event_source(data_class=CustomSMSSenderTriggerEvent)
def handler(event: CustomSMSSenderTriggerEvent, context):
    return handle_event(event=event)

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@knightmre knightmre requested a review from a team as a code owner May 29, 2024 06:45
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation tests labels May 29, 2024
Copy link

boring-cyborg bot commented May 29, 2024

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 29, 2024
@github-actions github-actions bot added feature New feature or functionality and removed documentation Improvements or additions to documentation labels May 29, 2024
@leandrodamascena
Copy link
Contributor

Hi @knightmre this is a super detailed PR with an impressive level of awesome docs/documentation. I'm working on other PRs and will schedule the first review of this PR for early next week.

Thanks

@knightmre
Copy link
Author

Hi @knightmre this is a super detailed PR with an impressive level of awesome docs/documentation. I'm working on other PRs and will schedule the first review of this PR for early next week.

Thanks

Hi, thanks for your time, I just found out I missed out on some tests so I'll be reworking this a little before your review.

@knightmre knightmre force-pushed the feat/update-cognito-events branch from f64d099 to 9002964 Compare May 29, 2024 10:12
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label May 29, 2024
@pull-request-size pull-request-size bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 29, 2024
@knightmre knightmre force-pushed the feat/update-cognito-events branch 3 times, most recently from a6e4c77 to 4bba674 Compare June 3, 2024 05:09
Copy link

codecov bot commented Jun 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.43%. Comparing base (e14e768) to head (b24173d).
Report is 561 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4423      +/-   ##
===========================================
+ Coverage    96.38%   96.43%   +0.05%     
===========================================
  Files          214      219       +5     
  Lines        10030    10623     +593     
  Branches      1846     1976     +130     
===========================================
+ Hits          9667    10244     +577     
- Misses         259      267       +8     
- Partials       104      112       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@knightmre knightmre force-pushed the feat/update-cognito-events branch from 4bba674 to 1129ce9 Compare June 11, 2024 03:22
@leandrodamascena
Copy link
Contributor

Reviewing this now.

Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @knightmre! Well done! This was one of the most detailed PRs I've looked at. Creating all those events in Cognito must have taken a lot of hard work and I'm sure you spent some days. I tried making some myself, and it took me over a day.

I just made a few small comments to your great work. 🚀

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
3.9% Duplication on New Code

See analysis details on SonarCloud

@knightmre knightmre force-pushed the feat/update-cognito-events branch from 1b7c873 to 036b3e0 Compare June 12, 2024 03:08
@knightmre
Copy link
Author

Hey @knightmre! Well done! This was one of the most detailed PRs I've looked at. Creating all those events in Cognito must have taken a lot of hard work and I'm sure you spent some days. I tried making some myself, and it took me over a day.

I just made a few small comments to your great work. 🚀

Hi @leandrodamascena Thanks for the review. I've included your comments and updated the PR.

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
3.9% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to say this again: amazing work @knightmre!

APPROVED!

@sthulb sthulb merged commit 81892c1 into aws-powertools:develop Jun 12, 2024
16 checks passed
Copy link

boring-cyborg bot commented Jun 12, 2024

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature New feature or functionality size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Update some outdated Cognito user pool event data classes
3 participants